Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Controlling the size of a transaction
You’ve already learned which statements start a transaction automatically. To summarize, these are:
You can also control the size of a transaction by adding the
TRANSACTIONkeyword to aDO,FOR EACH, orREPEATblock. This can force a transaction to be larger, but because of the statements that start a transaction automatically, you cannot use it to make a transaction smaller than Progress would otherwise make it.Take another look at the update procedure
saveOrder, in the sample logic procedureorderlogic.p, to see how transaction blocks are affected by changes to the procedure.As written, there is a
DO TRANSACTIONblock around the whole update of both the Order and any modified OrderLines:
The update of the Order and its OrderLines happens as a single transaction. If any errors are encountered in any of the updates, the entire transaction is backed out.
![]()
To verify this, you can generate a listing file as you’ve done earlier:
![]()
When you run this
COMPILEstatement, your listing file tells you, among other things, where all the transactions begin and end. This is very valuable information. You should always use a listing file in any complex procedure to make sure that your record scope and transaction scope are as you intended.Taking a look at this listing file, you can see that the
DO TRANSACTIONblock is a top-level block within its procedure, marked with a 1. TheDOblock inside it, where the Order is actually updated, is block level 2:
Further down, you can see that the
FOR EACHblock that operates on the OrderLines is also a nested block, at level 2 within the mainDO TRANSACTIONblock:
Now if you look at the end of the file, you see a summary of all the blocks. Here’s an excerpt from that part of the listing. It shows that the procedure blocks for the internal procedures
fetchOrderandsaveOrderare not transaction blocks:
This is a good thing. You never want your transactions to default to the level of a procedure, because they are likely to be larger than you want them to be. This means that record locks are held longer than necessary and that more records might be involved in a transaction than you intended.
Next you see that Progress identifies the first
DOblock at line 144 as a transaction block. This is because it has an explicitTRANSACTIONqualifier on it. The nestedDOblock two lines later is not a transaction block because aDOblock by itself does not mark a transaction.The
FOR EACHblock at line 164 is also marked as a transaction block:
What does this mean? Is this really a separate transaction? The answer is no, because the
FOR EACHblock is nested inside the largerDO TRANSACTIONblock. This code tells you that theFOR EACHblock would be a transaction block (because this is the nature ofFOR EACHblocks that perform updates). However, because it is nested inside a larger transaction, it becomes a subtransaction. Progress can back out changes made in a subtransaction within a larger transaction when an error occurs, and you can also do this yourself, as you’ll learn a little later in the "Subtransactions" section.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |